package cn.gailvlun.gll.presentation.emotion.drawer

import android.content.Context
import cn.gailvlun.gll.R
import cn.gailvlun.gll.net.emotion.Comment
import cn.gailvlun.gll.net.emotion.Emotion
import cn.gailvlun.gll.presentation.emotion.core.BaseAdapter
import org.jetbrains.annotations.NotNull


class EmotionDetail2Adapter : BaseAdapter<Any> {


    constructor(context: Context) : super(context) {
        addViewTypeToLayoutMap(Type.EMPTY.ordinal, R.layout.item_emotion_empty)
        addViewTypeToLayoutMap(Type.CONTENT.ordinal, R.layout.item_emotion_detail2_emotion)
        addViewTypeToLayoutMap(Type.LIKE_LIST_ICON.ordinal, R.layout.item_emotion_detail2_like_list)
        addViewTypeToLayoutMap(Type.COMMENT.ordinal, R.layout.item_emotion_detail2_comment)
        addViewTypeToLayoutMap(Type.COMMENT_HEADER.ordinal, R.layout.item_emotion_detail2_comment_header)
    }

    enum class Type {
        EMPTY,
        CONTENT,
        LIKE_LIST_ICON,
        COMMENT_HEADER,
        COMMENT
    }

    override fun removeCondition(@NotNull whichItem: Any, @NotNull certainItem: Any): Boolean {
        whichItem as Emotion
        certainItem as Emotion
        return whichItem.id == certainItem.id || super.removeCondition(whichItem, certainItem)
    }

    override fun notifyItemChangedCondition(whichItem: Any, certainItem: Any): Boolean {
        whichItem as Emotion
        certainItem as Emotion

        return false

    }

    fun findFirstPositionByViewType(type: Type): Int {
        for (i in mCollectionViewType.indices) {
            if (mCollectionViewType[i] == type.ordinal) {
                return i
            }
        }
        return -1
    }

    fun removeByViewType(type: Type) {
        for (i in mCollectionViewType.indices) {
            if (mCollectionViewType[i] == type.ordinal) {
                mCollectionViewType.removeAt(i)
                mCollection.removeAt(i)
                notifyItemRemoved(i)
                break
            }
        }
    }

    fun removeComment(comment: Comment) {
        for (i in mCollection.indices) {
            if (mCollection[i] == comment) {
                mCollection.removeAt(i)
                notifyItemRemoved(i)
                break
            }
        }
    }

}